<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>乘积小于 K 的子数组</title>
</head>
<body>
  <script>
    function fn(nums, k) {
      if (k === 0) {
        return 0;
      }
      let left = 0;
      let sum = 1;
      let count = 0;
      for (let right = 0; right < nums.length; right++) {
        sum *= nums[right];
        while (left <= right && sum >= k) {
          sum /= nums[left++]
        }
        if (left <= right) {
          count += right - left + 1
        }
      }
      return count
    }
    console.log(fn([10, 5, 2, 6], 100))
  </script>
</body>
</html>